package com.android.takegism.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import androidx.annotation.Nullable;

public class DbUtils {
    private static DbUtils instance = new DbUtils();
    private MyDbOpenHelper dbOpenHelper;

    public static DbUtils getInstance(){
        return instance;
    }

    public void setContext(@Nullable Context context,@Nullable String string) {
        dbOpenHelper = new MyDbOpenHelper(context,string,null,4);
    }

    public SQLiteDatabase getWritableDatabase(){
        if (dbOpenHelper == null){
            throw new RuntimeException("必须先使用setContext方法");
        }else{
            return dbOpenHelper.getWritableDatabase();
        }
    }

    public SQLiteDatabase getReadableDatabase(){
        if (dbOpenHelper == null){
            throw new RuntimeException("必须先使用setContext方法");
        }else{
            return dbOpenHelper.getReadableDatabase();
        }
    }


}
